const { DataTypes } = require('sequelize')
const sequelize = require('../config/database')

const Course = sequelize.define('Course', {
  id: {
    type: DataTypes.UUID,
    defaultValue: DataTypes.UUIDV4,
    primaryKey: true
  },
  title: {
    type: DataTypes.STRING,
    allowNull: false
  },
  description: {
    type: DataTypes.TEXT
  },
  coverImage: {
    type: DataTypes.STRING
  },
  videoUrl: {
    type: DataTypes.STRING
  },
  duration: {
    type: DataTypes.INTEGER,
    defaultValue: 0
  },
  price: {
    type: DataTypes.DECIMAL(10, 2),
    defaultValue: 0
  },
  originalPrice: {
    type: DataTypes.DECIMAL(10, 2)
  },
  level: {
    type: DataTypes.ENUM('初级', '中级', '高级'),
    defaultValue: '初级'
  },
  category: {
    type: DataTypes.STRING
  },
  tags: {
    type: DataTypes.JSON
  },
  instructor: {
    type: DataTypes.STRING
  },
  content: {
    type: DataTypes.JSON
  },
  requirements: {
    type: DataTypes.TEXT
  },
  objectives: {
    type: DataTypes.TEXT
  },
  isPublished: {
    type: DataTypes.BOOLEAN,
    defaultValue: false
  },
  publishedAt: {
    type: DataTypes.DATE
  },
  viewCount: {
    type: DataTypes.INTEGER,
    defaultValue: 0
  },
  purchaseCount: {
    type: DataTypes.INTEGER,
    defaultValue: 0
  },
  rating: {
    type: DataTypes.DECIMAL(3, 2),
    defaultValue: 0
  },
  ratingCount: {
    type: DataTypes.INTEGER,
    defaultValue: 0
  }
})

module.exports = Course
